Imports Microsoft.VisualBasic
Imports sk.DAL

Public Class CategoryObj
    Inherits BizObject
    Sub New(ByVal ID As String, ByVal name As String)
        _CategoryID = ID
        _Name = name
    End Sub

    Sub New()

    End Sub

    Private _CategoryID As Integer
    Public Property CategoryID() As Integer
        Get
            Return _CategoryID
        End Get
        Set(ByVal value As Integer)
            _CategoryID = value
        End Set
    End Property


    Private _Name As String
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Public Function CreateCategory() As Boolean
        Dim provider As CategoryProvider
        Dim cat As New Category
        cat.Name = _Name
        Try
            provider = sk.DAL.CategoryProvider.Instance
            provider.CreateCategory(Cat)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function DeleteCategory(ByVal Cat As Category) As Boolean
        Try
            Dim provider As CategoryProvider
            provider = sk.DAL.CategoryProvider.Instance
            provider.DeleteCategory(Cat.CategoryID)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Overloads Function GetAllCategories() As System.Collections.Generic.List(Of Category)
        Try
            Dim provider As CategoryProvider
            provider = sk.DAL.CategoryProvider.Instance

            Return provider.GetAllCategories
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Category)
        End Try
    End Function

    Public Overloads Function GetCategoryByID(ByVal CatID As Integer) As Boolean
        Try
            Dim provider As CategoryProvider
            Dim cat As New Category
            provider = sk.DAL.CategoryProvider.Instance
            cat = provider.GetCategory(CatID)
            _CategoryID = cat.CategoryID
            _Name = cat.Name
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function UpdateCategory(ByVal Cat As Category) As Boolean
        Try
            Dim provider As CategoryProvider
            provider = sk.DAL.CategoryProvider.Instance
            provider.UpdateCategory(Cat)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class


